package com.heima.wemedia.controller.v1;

import cn.hutool.core.util.ObjectUtil;
import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(@RequestParam("multipartFile") MultipartFile multipartFile) {
        if (ObjectUtil.isEmpty(multipartFile)) {
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        return this.wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 素材列表查询
     */
    @PostMapping("/list")
    public PageResponseResult<List<WmMaterial>> findList(@RequestBody WmMaterialDto dto) {
        return this.wmMaterialService.findList(dto);
    }

    //删除素材
    @DeleteMapping("/del_picture/{id}")
    public ResponseResult<AppHttpCodeEnum> deleteMaterial(@PathVariable("id") Integer id) {
        return this.wmMaterialService.deleteMaterial(id);
    }

    @GetMapping("cancel_collect/{id}")
    public ResponseResult<AppHttpCodeEnum> cancelCollect(@PathVariable("id") Integer id) {
        return this.wmMaterialService.cancelCollect(id);
    }

    @GetMapping("collect/{id}")
    public ResponseResult<AppHttpCodeEnum> collect(@PathVariable("id") Integer id) {
        return this.wmMaterialService.collect(id);
    }
}
